package com.example.demo.controller;

import com.example.demo.service.LoggerService;
import com.example.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/user3")
@Slf4j
public class UserController3 {
    @Autowired
    private UserService userInfo;

    @Autowired
    private LoggerService loggerService;

    @Transactional(propagation = Propagation.REQUIRED)
    @RequestMapping("/register")
    public  String register(String userName, String password){
        //插入用户表
        Integer result=userInfo.insert(userName,password);
        log.info("注册成功影响行数为：{}",result);
        //插入日志表
        loggerService.insert(userName,"用户注册");
        return "用户注册成功";
    }

}
